//
// Created by ta&to on 2022/10/28.
//

#ifndef HTTPSERVER_HTTP_RESPONSE_H
#define HTTPSERVER_HTTP_RESPONSE_H

#define HTTP_CONTINUE                  100
#define HTTP_SWITCHING_PROTOCOLS       101
#define HTTP_PROCESSING                102
#define HTTP_OK                        200
#define HTTP_CREATED                   201
#define HTTP_ACCEPTED                  202
#define HTTP_NO_CONTENT                204
#define HTTP_PARTIAL_CONTENT           206
#define HTTP_SPECIAL_RESPONSE          300
#define HTTP_MOVED_PERMANENTLY         301
#define HTTP_MOVED_TEMPORARILY         302
#define HTTP_SEE_OTHER                 303
#define HTTP_NOT_MODIFIED              304
#define HTTP_TEMPORARY_REDIRECT        307
#define HTTP_PERMANENT_REDIRECT        308
#define HTTP_BAD_REQUEST               400
#define HTTP_UNAUTHORIZED              401
#define HTTP_FORBIDDEN                 403
#define HTTP_NOT_FOUND                 404
#define HTTP_NOT_ALLOWED               405
#define HTTP_REQUEST_TIME_OUT          408
#define HTTP_CONFLICT                  409
#define HTTP_LENGTH_REQUIRED           411
#define HTTP_PRECONDITION_FAILED       412
#define HTTP_REQUEST_ENTITY_TOO_LARGE  413
#define HTTP_REQUEST_URI_TOO_LARGE     414
#define HTTP_UNSUPPORTED_MEDIA_TYPE    415
#define HTTP_RANGE_NOT_SATISFIABLE     416
#define HTTP_MISDIRECTED_REQUEST       421
#define HTTP_TOO_MANY_REQUESTS         429
#define HTTP_CLOSE                     444
#define HTTP_NGINX_CODES               494
#define HTTP_REQUEST_HEADER_TOO_LARGE  494
#define HTTPS_CERT_ERROR               495
#define HTTPS_NO_CERT                  496
#define HTTP_TO_HTTPS                  497
#define HTTP_CLIENT_CLOSED_REQUEST     499
#define HTTP_INTERNAL_SERVER_ERROR     500
#define HTTP_NOT_IMPLEMENTED           501
#define HTTP_BAD_GATEWAY               502
#define HTTP_SERVICE_UNAVAILABLE       503
#define HTTP_GATEWAY_TIME_OUT          504
#define HTTP_VERSION_NOT_SUPPORTED     505
#define HTTP_INSUFFICIENT_STORAGE      507

struct responseContext {
    int fd;
    int fd_errno;
    int client_fd;
    int client_fd_errno;
    dts head;
    dts prev_buf;
    char* buf;
    int buf_len;
    rep_attr_t *attr;
    struct http_socket_event_s *hset;
    struct body_stream_t rep_stream;
};
typedef void (*before_response_callback)(struct responseContext *rpctx);
typedef void (*running_response_callback)(struct responseContext *rpctx);
typedef void (*after_response_callback)(struct responseContext *rpctx);

void _file_rep_analysis_head(struct responseContext *response);
void _file_before_response_callback(struct responseContext *rpctx);
void _file_running_response_callback(struct responseContext *rpctx);
void _file_after_response_callback(struct responseContext *rpctx);

void _port_rep_analysis_head(struct responseContext *response);
void _port_before_response_callback(struct responseContext *rpctx);
void _port_running_response_callback(struct responseContext *rpctx);
void _port_after_response_callback(struct responseContext *rpctx);

void _clear_rep_head(struct responseContext *response);
void response_control(http_inner_response_before_facade_t *hirpbef);
void init_rep(struct responseContext* response);
void init_rep_attr(struct response_head_attr_s* attr);
#endif //HTTPSERVER_HTTP_RESPONSE_H
